package BackTrack.万诺;

import org.junit.Test;

public class 亲7数_全排列 {
    @Test
    public void test() {
        int[] p = {1, 1, 2};
        System.out.println("RES: " + qin7(p));
    }

    int count = 0;
    int[] nums;
    boolean[] vis;
    int cur = 0;

    public int qin7(int[] p) {
        nums = p;
        vis = new boolean[nums.length];

        int k = 3; // 初别直接bT(0), 标一下含义
        bT(k);
        return count;
    }

    private void bT(int k) {
        if (numWeiShu(cur) == k) {
            if (cur % 7 == 0) {
                count++;
            }
            return;
        }

        for (int i = 0; i < nums.length; i++) {
            if (vis[i]) {
                continue;
            }
            cur = cur * 10 + nums[i];
            vis[i] = true; // debug 在cur赋值完 后 打
            bT(k);
            cur /= 10;
            vis[i] = false;
        }
    }

    private int numWeiShu(int a) {
        return (a + "").length();
    }
}
